// pages/coles/coles.js
import {
  ajax,
  src,
  util
} from "../../utils/util.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    vertical: false,
    autoplay: true,
    circular:true,
    interval: 2000,
    duration: 500,
    banners:'',
    shoplist:"",
  },
  //展示更多优惠
  zhanshi: function (e) {
    var idx = e.currentTarget.dataset.upid;
    if (this.data.shoplist[idx].shownum == 1) {
      var str = "shoplist[" + idx + "].shownum"
      this.setData({
        [str]: 100
      })
    } else {
      var str = "shoplist[" + idx + "].shownum"
      this.setData({
        [str]: 1
      })
    }
    console.log(this.data.shoplist,'list')
  },
  //897超市搜索
  colesSearch: function (){
    wx.navigateTo({
      url: '/pages/coles-search/search',
    })
  },
  //跳转店铺首页
  shop:function(e){
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/shop-homepage/homepage?ID=' + id,
    })
  },
  //跳转商品详情
  details: function (e) {
    let goodsid = e.currentTarget.dataset.goodsid;
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/supermarket-details/details?shopID=' + id + '&ID=' + goodsid,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  //获取轮播图
  getbanner:function(){
    ajax('/api/Diagram/Get?requestContent=' + JSON.stringify({
      token: wx.getStorageSync('Access_token'),
      Province: wx.getStorageSync('address_component').province,
      City: wx.getStorageSync('address_component').city,
      District: wx.getStorageSync('address_component').district,
      BroadCastType:1
    }),{
        header: {
          'Accept': 'application/x-www-form-urlencoded', // 默认值
        },
        method: "get",
      }, res => {
        console.log(res,'banner')
        this.setData({
          banners: res.Models
        })
      })
  },
  //获取数据
  getshoplist:function(){
    ajax('/api/ShopBaJiuQi/Get?requestContent=' + JSON.stringify({
      token: wx.getStorageSync('Access_token'),
      ShopName: "",
      Province: wx.getStorageSync('address_component').province,
      City: wx.getStorageSync('address_component').city,
      District: wx.getStorageSync('address_component').district,
      lng: wx.getStorageSync('longitude'),
      lat: wx.getStorageSync('latitude')
    }), {
        header: {
          'Accept': 'application/x-www-form-urlencoded', // 默认值
        },
        method: "get",
      }, res => {
        console.log(res)
        var shoplist = res.Models
        for (var x in shoplist) {
          shoplist[x].shownum = 1
        }
        this.setData({
          shoplist: shoplist
        })
      })
  },
  onLoad: function (options) {
    this.getbanner()
    this.getshoplist()
    

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})